home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 28.4 KB | 1,100 lines | [TEXT/MPS ] |
- /*
- File: UDocumentSecondStomach.cp
-
- Contains: *** put contents here ***
-
- Written by: Steve Datnow
-
- Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 8/25/93 ASB When error in config dialogs show not dispose of dialog
- 8/18/93 SLD Get popups working
- 8/17/93 SLD Make checkboxes use longs and fix program error when 0 length config string is returned
- 4/2/93 KSS Change the defn of status items from starting with •• to consisting of all lower case characters.
- 1/7/92 SLD Created
-
- To Do:
- */
-
-
-
- #ifndef __UDOCUMENTSecondStomach__
- #include "UDocumentSecondStomach.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include <UViewServer.h>
- #endif
-
- #ifndef __UPRINTING__
- #include <UPrinting.h>
- #endif
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #if false
- #ifndef __UCOMMANDSecondStomach__
- #include "UCommandSecondStomach.h"
- #endif
- #endif
-
- #ifndef __UViewStatusInfo__
- #include "UViewStatusInfo.h"
- #endif
-
- #ifndef __UGLOBALSSecondStomach__
- #include "UGlobalsSecondStomach.h"
- #endif
-
- #ifndef __STDIO__
- #include <StdIO.h>
- #endif
-
- /****************************** Constants ******************************/
-
- const kSecondStomachWindowID = 1000;
-
- /****************************** TDocumentSecondStomach ******************************/
-
- long TDocumentSecondStomach::fUniqueSessionID = 0;
-
- /***********************************|****************************************/
- #pragma segment AOpen
-
- pascal void TDocumentSecondStomach::Initialize() // Override
- {
- inherited::Initialize();
- }
-
- /***********************************|****************************************/
- OSErr GetTargetAddress (Str255& myPrompt, Str255& myAppStr, PortInfoRec& myPortInfo, AEAddressDesc& targetAddress,TargetID& toTargetID)
-
- {
- OSErr myErr;
-
- myErr = PPCBrowser((ConstStr255Param) myPrompt,(ConstStr255Param) myAppStr, FALSE,toTargetID.location,myPortInfo, nil, "");
-
- if (myErr == noErr)
- {
- toTargetID.name = myPortInfo.name;
- return AECreateDesc(typeTargetID,(Ptr) &toTargetID, sizeof(toTargetID), targetAddress);
- }
- else
- return myErr;
- }
-
- /***********************************|****************************************/
- #pragma segment AOpen
-
- pascal void TDocumentSecondStomach::IDocumentSecondStomach(TFile* itsFile,
- OSType itsCreator)
- {
- fItemsToBeMonitored = nil;
- //fSendAliveCounter = 0;
- fTimerHandler= nil;
- fStatusList = nil;
- fDocSessionID = fUniqueSessionID++;
- fLog = nil;
- fStatus = nil;
- fDisconnected = true;
-
- this->IFileBasedDocument(itsFile,itsCreator);
-
- TTimerHandler* theTimerHandler = new TTimerHandler();
- FailNIL(theTimerHandler);
- theTimerHandler->ITimerHandler(this);
- theTimerHandler->SetIdleFreq(60); // 5 seconds
- gApplication->InstallCohandler((TEventHandler*) theTimerHandler, TRUE);
- fTimerHandler = theTimerHandler;
-
- // SetIdleFreq(450);
- }
-
- /***********************************|****************************************/
- #pragma segment AOpen
-
- pascal OSErr TDocumentSecondStomach::EstablishSession()
- {
- TAppleEvent* theMessage;
- TAppleEvent* theReplyEvent = NULL;
-
- theMessage = new TAppleEvent;
- theMessage->IAppleEvent(kSSEventClass, 'log ', fTargetAddress, kAEWaitReply);
- theMessage->SetTimeoutVal(900);
-
- // Send our sessionID to the application to be monitored in an AppleEvent.
- theMessage->WriteLong('SSID',fDocSessionID);
-
- // Two cases the Apple Event may time out or a bogus apple event may be returned
- FailInfo fi;
- if (fi.Try())
- {
- theReplyEvent = theMessage->Send();
- fi.Success();
- }
- else
- {
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- if (fi.error != errAETimeout)
- return fi.error;
- }
-
- // Well, the send happened corrertly, so make sure that the other application
- // supports monitoring.
- long willHandle = 0;
- if (theReplyEvent)
- willHandle = theReplyEvent->ReadLong('SUPT'); // Make sure it is not a bogus reply
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- theReplyEvent = (TAppleEvent*) FreeIfObject((TObject*) theReplyEvent);
-
- if (willHandle != cSupportMonitoring) {
- return -1;
- }
-
- MonitoringChange(false);
-
- return noErr;
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::SendItemsToBeLogged()
- {
- TAppleEvent* theMessage;
-
- TDynamicArray* theItemsToBeMonitored = fItemsToBeMonitored;
- if (theItemsToBeMonitored != nil) {
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'itms', fTargetAddress, kAENoReply);
- theMessage->WriteLong('SSID',fDocSessionID);
- theMessage->WritePtrList('INFO',typeLongInteger,theItemsToBeMonitored);
- theMessage->Send();
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- ResetTimer();
- }
- }
-
- /***********************************|****************************************/
- #pragma segment AClose
-
- pascal void TDocumentSecondStomach::Disconnect() {
- if ((fDisconnected == false)) {
- TAppleEvent* theMessage;
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'stop', fTargetAddress, kAENoReply);
- theMessage->WriteLong('SSID',fDocSessionID);
- FailInfo fi;
- if (fi.Try())
- {
- theMessage->Send(); // Don't care if we fail
- fi.Success();
- }
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- fDisconnected = true;
- }
- }
-
- pascal void TDocumentSecondStomach::Free() // Override
- {
-
- Disconnect();
-
- if (fTimerHandler) {
- gApplication->InstallCohandler((TEventHandler*) fTimerHandler, FALSE);
- fTimerHandler = (TTimerHandler*) FreeIfObject((TObject*) fTimerHandler);
- }
-
- fStatusList = (TStatusItemList*) FreeListIfObject((TList*) fStatusList);
- fItemsToBeMonitored = (TDynamicArray*) FreeIfObject((TObject*) fItemsToBeMonitored);
-
- inherited::Free();
- }
-
- /***********************************|****************************************/
- #pragma segment AClose
-
- pascal void TDocumentSecondStomach::FreeData() // Override
- {
- inherited::FreeData();
- }
-
- /***********************************|****************************************/
- #pragma segment AOpen
-
- pascal void TDocumentSecondStomach::DoInitialState() // Override
- {
- inherited::DoInitialState();
- fItemsToBeMonitored = nil;
- fReOpening = false;
- }
-
- /***********************************|****************************************/
- #pragma segment AOpen
-
- /***********************************|****************************************/
-
- pascal CompareResult CompareIDs(TObject* anItem, void* staticLink)
-
- {
- long e1 = ((TStatusItem*)anItem)->GetID();
- long e2 = (long) staticLink;
-
- if (e1 == e2)
- return kItem1EqualItem2;
- else
- if (e1 < e2)
- return kItem1LessThanItem2;
- else
- return kItem1GreaterThanItem2;
- }
-
- /***********************************|****************************************/
-
- Boolean IsCharLegalInViewIdentifier ( char c )
- {
- return ! (( c >= 'a' ) && ( c <= 'z' ) || (c == ' '));
- }
-
- /***********************************|****************************************/
-
- Boolean IsViewIdentifierAStatusItem ( IDType viewType )
- { unsigned long l = (unsigned long) viewType;
- char c1 = (char) ((l & (unsigned long) 0xff000000) >> 24);
- char c2 = (char) ((l & (unsigned long) 0x00ff0000) >> 16);
- char c3 = (char) ((l & (unsigned long) 0x0000ff00) >> 8);
- char c4 = (char) ((l & (unsigned long) 0x000000ff) >> 0);
-
- Boolean result = (IsCharLegalInViewIdentifier(c1) ) && (IsCharLegalInViewIdentifier(c2) ) &&
- (IsCharLegalInViewIdentifier(c3) ) && (IsCharLegalInViewIdentifier(c4) &&
- ((c1 != 'V') || (c2 != 'W')) );
-
- return result;
- }
-
- /***********************************|****************************************/
-
- pascal void BuildStatusTable(TView* theSubView, void* staticLink)
- {
- // IDType t = theSubView->fIdentifier;
- char identifierStr[5];
- * ( long *) &identifierStr[0] = theSubView->fIdentifier;
- identifierStr[4] = 0;
-
- if (IsViewIdentifierAStatusItem ( theSubView->fIdentifier ) )
- {
- // Find whether this item is already in our list of identifiers
- TStatusItemList* theList = (TStatusItemList*) staticLink;
- TStatusItem* aStatusItem = (TStatusItem*) theList->Search(&CompareIDs, (void*) theSubView->fIdentifier);
-
- // If it's not already in the list, create a new statusItem and save it in
- // the list.
- if (aStatusItem == nil) {
- // fprintf (stderr, "BuildStatusTable::'%s' is being added.\n", identifierStr);
-
- aStatusItem = new TStatusItem;
- aStatusItem->SetID(theSubView->fIdentifier);
- aStatusItem->SetDescType(typeWildCard);
-
- theList->Insert((TObject*) aStatusItem);
- }
- else
- {
- // fprintf (stderr, "BuildStatusTable::'%s' is already in table.\n", identifierStr);
- }
-
- // And make this view item depend on this status item.
- aStatusItem->AddDependent((TObject*) theSubView);
- aStatusItem->SetInfo(NULL,0,typeWildCard);
- }
- else
- {
- // fprintf (stderr, "BuildStatusTable::'%s' is not a legal identifier.\n", identifierStr);
- }
-
- theSubView->EachSubView (BuildStatusTable, (void*) staticLink );
- }
-
- /***********************************|****************************************/
-
- pascal void AddToList(TObject* item, void* staticLink)
- {
- TStatusItem* theStatusItem = (TStatusItem*) item;
- IDType theID = theStatusItem->GetID();
- TDynamicArray* theItemsToBeMonitored = (TDynamicArray*) staticLink;
- theItemsToBeMonitored->InsertElementsBefore(theItemsToBeMonitored->GetSize()+1,(Ptr) &theID,1);
- }
-
- /***********************************|****************************************/
-
- void PrintViewAndSubview ( TView * aView , unsigned long depth = 0)
- {
- char viewIDStr[8];
- * ( long *) &viewIDStr[0] = aView->fIdentifier;
- viewIDStr[4] = 0;
-
- #if 0
- for (unsigned long i = 0; i < depth; ++i)
- fprintf (stderr, " ");
- fprintf (stderr, "View: '%s' (%d children)\n", viewIDStr, aView->CountSubViews());
-
- CSubViewIterator anIterator ( aView );
- for (unsigned long count = 1; count <= aView->CountSubViews(); ++count) {
- TView* childView = (TView*) aView->fSubViews->At(count);
-
- char childIDStr[8];
- * ( long *) &childIDStr[0] = childView->fIdentifier;
- childIDStr[4] = 0;
-
- for (i = 0; i < depth; ++i)
- fprintf (stderr, " ");
- fprintf (stderr, "%2d. '%s' (%d children)\n", count, childIDStr, childView->CountSubViews());
- }
- #endif
-
- CSubViewIterator anIterator2 ( aView );
- for (TView* childView = anIterator2.FirstSubView(); anIterator2.More(); childView = anIterator2.NextSubView())
- PrintViewAndSubview ( childView , depth + 1);
-
- // for (i = 0; i < depth; ++i)
- // fprintf (stderr, " ");
- // fprintf (stderr, "View: '%s' DONE\n", viewIDStr, aView->CountSubViews());
-
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::DoMakeViews(Boolean /*forPrinting*/) // Override
- {
- TWindow* aWindow = NULL;
- TStdPrintHandler* aHandler = NULL;
- TView* aView = NULL;
-
- TStatusItemList* statusList = new TStatusItemList;
- statusList->IList();
-
-
- FailInfo fi;
- if (fi.Try())
- {
- FailNIL(aWindow = gViewServer->NewTemplateWindow(kSecondStomachWindowID, this));
-
- AEAddressDesc theTargetAddress;
- PortInfoRec thePortInfoRec;
- TargetID theTargetID;
- Str255 temp;
- OSErr err;
-
- temp[0] = 0;
-
- if (fReOpening) {
- theTargetID = fTargetID;
- err = AECreateDesc(typeTargetID,(Ptr) &theTargetID, sizeof(theTargetID), theTargetAddress);
- }
- else {
- // Call up the PPC browser to find gateway
- err = GetTargetAddress(temp, temp, thePortInfoRec, theTargetAddress, theTargetID);
- }
-
- if (err == userCanceledErr)
- Failure(noErr,messageCancelled);
- else
- FailOSErr(err);
-
- fTargetID = theTargetID;
- fTargetAddress = theTargetAddress;
-
- Handle h = GetResource('mWin',1000);
- short x = (short) *((long*) (*h));
- short y = (short) *((long*) (*h+4));
- CPoint itsMinSize = CPoint(x,y);
-
- CPoint itsMaxSize = CPoint((short) aWindow->fSize.h,(short) aWindow->fSize.v);
- aWindow->SetResizeLimits(itsMinSize,itsMaxSize);
-
- if (fReOpening == true) {
- aWindow->SetFrame(fWinFrame,kDontRedraw);
- aWindow->ForceOnScreen();
- fReOpening = false;
- }
- else {
- VRect frame;
- SetChangeCount(1); // Save menu items active now
- aWindow->GetFrame(frame);
- fWinFrame = frame;
- }
-
- aView = (TView*) (aWindow->FindSubView('scrl')); // Must cast because FindSubView returns TView
- FailNIL(aView);
-
- aHandler = new TStdPrintHandler;
- aHandler->IStdPrintHandler(this, // its document
- aView, // its view
- !kSquareDots, // does not have square dots
- kFixedSize, // horzontal page size is fixed
- kFixedSize); // vertical page size is fixed
-
-
- PrintViewAndSubview ( aView );
-
-
- aView->EachSubView(BuildStatusTable, (void*) statusList);
- fStatusList = statusList;
- TDynamicArray* theItemsToBeMonitored;
- FailNIL(theItemsToBeMonitored = new TDynamicArray());
- theItemsToBeMonitored->IDynamicArray(statusList->GetSize(),sizeof(long));
- statusList->Each(&AddToList,(void*) theItemsToBeMonitored);
- fItemsToBeMonitored = theItemsToBeMonitored;
-
- if (aWindow != nil) {
- fStatus = (TViewMonitorStatus*) (aWindow->FindSubView('stus'));
- }
-
- fLog = (TViewlogStatusInfo*) (aView->FindSubView( 'GLOG'));
- AddToLog("Monitor Started");
-
- err = EstablishSession();
- if (err != noErr) {
- SysBeep(5);
- MonitoringChange(true);
- }
- else
- SendItemsToBeLogged();
-
- fi.Success();
- }
- else
- {
- fi.ReSignal();
- };
- }
-
- /***********************************|****************************************/
- #pragma segment AWriteFile
-
- pascal void TDocumentSecondStomach::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes) // Override
- {
- inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
- }
-
- /***********************************|****************************************/
- #pragma segment ASelCommand
-
- pascal void TDocumentSecondStomach::DoMenuCommand(CommandNumber aCommandNumber) // Override
- {
- /*
- This method is overridden to handle menu items which are enabled when this document
- is in the target chain. In this example, this is true when the document is open and
- its window is the active window. The inherited method should always be called so
- that MacApp can allow successor objects in the target chain (i.e. the application) to
- handle THEIR menu items.
- */
- switch (aCommandNumber)
- {
- case 2001:
- {
- TWindow * aWindow;
- IDType dismisser;
-
- FailNIL(aWindow = gViewServer->NewTemplateWindow(1001, this));
- dismisser = aWindow->PoseModally();
- aWindow->CloseAndFree();
- }
- break;
- case 4000:case 4002:
- {
- TWindow * aWindow;
- IDType dismisser;
-
- FailNIL(aWindow = gViewServer->NewTemplateWindow(aCommandNumber, this));
- dismisser = aWindow->PoseModally();
- aWindow->CloseAndFree();
- }
- break;
-
- default:
- inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
-
- /***********************************|****************************************/
- #pragma segment AReadFile
-
- pascal void TDocumentSecondStomach::DoRead(TFile* aFile,
- Boolean forPrinting) // Override
- {
- TargetID theTID;
-
- inherited::DoRead(aFile,forPrinting);
- VRect winFrame;
- long theSize = sizeof(winFrame);
- FailOSErr(aFile->ReadData(&winFrame,theSize)); // Window position
- theSize = sizeof(theTID);
- FailOSErr(aFile->ReadData(&theTID,theSize)); // Target being monitored
- fWinFrame = winFrame;
- fTargetID = theTID;
-
- fReOpening = true;
- }
- /***********************************|****************************************/
- #pragma segment ARes
-
- pascal void TDocumentSecondStomach::DoSetupMenus() // Override
- {
- /*
- This method is overridden to enable menu items which should be enabled when this
- object is in the target chain. MacApp initially disables all menu items, then
- lets the objects in the target chain enable those items they handle.
-
- A document object is in the target chain when its window is the active window.
-
- The inherited method is called so that TDocument can enable document-level menu items
- like "Save…". This also ensures that objects further up the target chain (the application)
- can set up THEIR menus.
- */
- inherited::DoSetupMenus();
-
- //Enable(2001,TRUE);
- Enable(4000,TRUE);
- Enable(4002,TRUE);
- }
-
- /***********************************|****************************************/
- #pragma segment AWriteFile
-
- pascal void TDocumentSecondStomach::DoWrite(TFile* aFile,
- Boolean makingCopy) // Override
- {
- inherited::DoWrite(aFile,makingCopy);
- long theSize = sizeof(VRect);
- VRect winSize;
- TargetID tID;
-
- TWindow* window = (TWindow*) fWindowList->At(1);
- window->GetFrame(winSize);
- FailOSErr(aFile->WriteData(&winSize,theSize));
-
- tID = fTargetID;
- theSize = sizeof(tID);
- FailOSErr(aFile->WriteData(&tID,theSize));
- }
-
- /***********************************|****************************************/
-
- pascal long TDocumentSecondStomach::GetSessionID()
-
- {
- return fDocSessionID;
- }
-
- /***********************************|****************************************/
-
- pascal void GetUpdatedValue(TObject* anItem, void* staticLink) {
- TAppleEvent* theMessage = (TAppleEvent*) staticLink;
- TStatusItem* statusItem = (TStatusItem*) anItem;
- CStr255 newData;
- long newDataSize;
- DescType actualType;
- DescType desiredType = typeWildCard;
-
- FailInfo fi;
- if (fi.Try())
- {
- theMessage->ReadParameterPtr(statusItem->GetID(),
- typeWildCard,
- actualType,
- (Ptr) &newData,
- sizeof(newData),
- newDataSize);
-
- { char idStr[8];
- * (OSType*) idStr = statusItem->GetID();
- idStr[4] = 0;
-
- newData[newData[0]] = 0;
- // fprintf (stderr, "GetUpdatedValue: '%s' = '%s'\n", idStr, (char*) &newData[1]);
- }
-
- statusItem->SetInfo((void*) &newData, newDataSize, actualType);
-
- fi.Success();
- }
- else
- {
- if (fi.error != errAEDescNotFound)
- fi.ReSignal();
- };
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::MonitoringChange(Boolean stopMonitoring)
-
- {
- if (fWindowList->GetSize() > 0) {
- if (stopMonitoring == false) {
- fDisconnected = false;
- SetStatus("");
- }
- else {
- SetStatus("Not Responding");
- AddToLog("Unable to Monitor");
- fDisconnected = true;
- }
-
- Boolean done = false;
- CStr255 logID;
- TView* aView;
- TControl* tView;
- TWindow* aWindow;
- short index = 1;
-
- aWindow = (TWindow*) fWindowList->At(1);
- FailNIL( aWindow );
-
- aView = (TView*) (aWindow->FindSubView('scrl'));
- if (aView == nil)
- FailNIL(aView);
-
- /* This Grays any views that we want grayed when disconnected */
-
- while (done == false) {
- GetIndString(logID, kViewsToGreyWhenDisconnected, index);
-
- if (logID.Length() == 4) {
- tView = (TControl*) (aView->FindSubView( * ((long*) (&logID[1]))));
- if (tView)
- tView->DimState(stopMonitoring, kRedraw);
- }
- else
- done = true;
-
- index++;
- }
- }
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::HandleStatusInfo(TAppleEvent* theMessage) {
- if (fStatusList) {
- fStatusList->Each(&GetUpdatedValue, (void*) theMessage);
- ResetTimer();
-
- if (fDisconnected == true) {
- MonitoringChange(false);
- }
- }
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::ResetTimer()
-
- {
- unsigned long secs;
- GetDateTime(secs);
- fHeartBeat = secs;
- }
-
- /***********************************|****************************************/
-
- pascal Boolean TDocumentSecondStomach::TimerExpired()
-
- {
- // This should be greater then the interval between updates from the server (30)
- const unsigned long kSecondsBetweenChecks = 45;
- unsigned long secs;
-
- GetDateTime(secs);
- if ((secs - fHeartBeat) > kSecondsBetweenChecks) {
- return true;
- }
- else {
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::BlinkStatus()
-
- {
- if (fStatus != nil)
- fStatus->BlinkText();
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::SetStatus(CStr255 message)
- {
- if (fStatus != nil)
- fStatus->SetText(message, kRedraw);
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::AddToLog(CStr255 message)
-
- {
- if (fLog != nil) {
- fLog->AddToLog(message);
- }
- }
- /***********************************|****************************************/
-
- pascal Boolean TDocumentSecondStomach::DoIdle(IdlePhase)
- {
- return FALSE;
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::SendButtonMessage(long buttonId)
-
- {
- TAppleEvent* theMessage;
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'butt', fTargetAddress, kAENoReply);
- theMessage->WriteLong('SSID',fDocSessionID);
- theMessage->WriteLong('MCMD',buttonId);
- FailInfo fi;
- if (fi.Try())
- {
- theMessage->Send(); // Don't care if we fail
- fi.Success();
- }
- else
- {
- }
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- }
-
- pascal void TDocumentSecondStomach::SendConfigMessage(TView* theView) {
- TAppleEvent* theMessage;
- TAppleEvent* theReplyEvent = NULL;
- CStr255 configParam;
- short configIndex;
- long checkValue;
-
- const kConfigStringList = 7000;
-
- /* Get user value */
- configIndex = theView->fUserArea;
-
- /* Get the config parameter name */
- GetIndString(configParam,kConfigStringList,configIndex);
-
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'sfig', fTargetAddress, kAEWaitReply);
- theMessage->WriteLong('SSID',fDocSessionID);
-
- /* Write config parameter to outgoing ae */
- theMessage->WriteString('WFIG',configParam);
-
- if (theView->IsMemberClass(GetClassIDFromName("TEditText"))) {
- ((TEditText*) theView)->GetText(configParam);
- theMessage->WriteString('FIGV', configParam);
- }
- else if (theView->IsMemberClass(GetClassIDFromName("TCheckBox"))) {
- if (((TCheckBox*) theView)->IsOn())
- checkValue = 1;
- else
- checkValue = 0;
- theMessage->WriteLong('FIGV', checkValue);
- }
- else if (theView->IsMemberClass(GetClassIDFromName("TPopup"))) {
- short i = ((TPopup*) theView)->GetCurrentItem();
- ((TPopup*) theView)->GetItemText(i,configParam);
-
- theMessage->WriteString('FIGV', configParam);
- }
-
- FailInfo fi;
- if (fi.Try())
- {
- theReplyEvent = theMessage->Send(); // Don't care if we fail
- fi.Success();
- }
- else
- {
- }
-
- /* Set the parameter */
- if (theReplyEvent)
- {
- theReplyEvent->ReadString('FIGR', configParam);
- /* This is the result of the Configuration change */
- if (configParam.Length() != 0) {
- TWindow * aWindow;
- IDType dismisser;
- TStaticText* t;
-
- FailNIL(aWindow = gViewServer->NewTemplateWindow(1002, this));
- t = (TStaticText*) aWindow->FindSubView('MESS');
- if (t) {
- t->SetText(configParam, kRedraw);
- dismisser = aWindow->PoseModally();
- }
- aWindow->CloseAndFree();
- FailOSErr(-1);
- }
- }
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- theReplyEvent = (TAppleEvent*) FreeIfObject((TObject*) theReplyEvent);
- }
-
- pascal void TDocumentSecondStomach::GetConfigValue(TView* theView) {
- TAppleEvent* theMessage;
- TAppleEvent* theReplyEvent = NULL;
- CStr255 configParam;
- short configIndex;
-
- const kConfigStringList = 7000;
-
- /* Get user value */
- configIndex =theView->fUserArea;
-
- /* Get the config parameter name */
- GetIndString(configParam,kConfigStringList,configIndex);
-
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'gfig', fTargetAddress, kAEWaitReply);
- theMessage->WriteLong('SSID',fDocSessionID);
-
- /* Write config parameter to outgoing ae */
- theMessage->WriteString('WFIG',configParam);
-
- FailInfo fi;
- if (fi.Try())
- {
- theReplyEvent = theMessage->Send(); // Don't care if we fail
- fi.Success();
- }
- else
- {
- }
-
- /* Set the parameter */
- if (theReplyEvent)
- {
- long checkValue;
- FailInfo fi;
- if (fi.Try()) // Might not get a value - if so leave field blank
- {
- if (theView->IsMemberClass(GetClassIDFromName("TEditText"))) {
- theReplyEvent->ReadString('FIGV', configParam);
- ((TEditText*) theView)->SetText(configParam,kRedraw);
- }
- else if (theView->IsMemberClass(GetClassIDFromName("TCheckBox"))) {
- checkValue = theReplyEvent->ReadLong('FIGV');
- if (checkValue == 1)
- ((TCheckBox*) theView)->SetState(true,kRedraw);
- else
- ((TCheckBox*) theView)->SetState(false,kRedraw);
- }
- else if (theView->IsMemberClass(GetClassIDFromName("TPopup"))) {
- TPopup* p;
- short i;
- CStr255 t;
- Boolean done = FALSE;
-
- p = (TPopup*) theView;
- p->SetCurrentItem(1, kRedraw);
- theReplyEvent->ReadString('FIGV', configParam);
- i = 2;
- while (!done) {
- p->GetItemText(i,t);
- if (RelString(t,configParam,FALSE,TRUE) == 0) {
- p->SetCurrentItem(i, kRedraw);
- done = TRUE;
- }
- i++;
- }
-
- }
-
- fi.Success();
- }
- else
- {
- }
- }
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- theReplyEvent = (TAppleEvent*) FreeIfObject((TObject*) theReplyEvent);
- }
-
- /***********************************|****************************************/
-
- pascal void TDocumentSecondStomach::SendAliveMessage()
-
- {
- // const kMinutesBetween = 1;
-
- // fSendAliveCounter++;
- // if (fSendAliveCounter > kMinutesBetween * 4) {
- TAppleEvent* theMessage;
- FailNIL(theMessage = new TAppleEvent);
- theMessage->IAppleEvent(kSSEventClass, 'alve', fTargetAddress, kAENoReply);
- theMessage->WriteLong('SSID',fDocSessionID);
- FailInfo fi;
- if (fi.Try())
- {
- theMessage->Send(); // Don't care if we fail
- fi.Success();
- }
- else
- {
- }
-
- theMessage = (TAppleEvent*) FreeIfObject((TObject*) theMessage);
- // fSendAliveCounter = 0;
- // }
- }
-
- /***********************************|****************************************/
-
- pascal void TTimerHandler::ITimerHandler(TDocumentSecondStomach* parentDoc) {
- fParentDoc = parentDoc;
- fBaseTimer = TickCount();
- this->IEventHandler(NULL);
- }
-
- /***********************************|****************************************/
-
- pascal Boolean TTimerHandler::DoIdle(IdlePhase)
-
- {
- fParentDoc->BlinkStatus();
-
- if (fParentDoc->TimerExpired()) {
- OSErr err = fParentDoc->EstablishSession(); // This will fail out if cannot establish a session
- if (err == noErr) {
- fParentDoc->SendItemsToBeLogged();
- }
- else {
- if (fParentDoc->fDisconnected == false) {
- fParentDoc->MonitoringChange(true);
- fParentDoc->AddToLog("Restart Monitoring");
- }
- }
- fParentDoc->ResetTimer();
- }
- else {
- if ((TickCount() - fBaseTimer) > 3600) { // Every minute
- fBaseTimer = TickCount();
- fParentDoc->SendAliveMessage();
- }
- }
-
- return FALSE;
- }
- /***********************************|****************************************/
-
- Boolean IsViewIdentifierAConfigItem ( IDType viewType )
- { unsigned long l = (unsigned long) viewType;
- char c1 = (char) ((l & (unsigned long) 0xff000000) >> 24);
-
- Boolean result = (c1 == 'C');
-
- return result;
- }
-
- /***********************************|****************************************/
-
- pascal void SendConfigChange(TView* theSubView, void* staticLink)
- {
- CStr255 info;
-
- if (IsViewIdentifierAConfigItem (theSubView->fIdentifier))
- {
- TDocumentSecondStomach* s = (TDocumentSecondStomach*) staticLink;
- s->SendConfigMessage(theSubView);
- }
- else
- {
- }
-
- theSubView->EachSubView (SendConfigChange, (void*) staticLink );
- }
-
- /***********************************|****************************************/
-
- pascal void TDialogViewConfig::DoEvent(EventNumber eventNumber, TEventHandler* source,
- TEvent* event)//Override
- {
- if (source->fIdentifier == 'SAVE') {
- FailInfo fi;
- if (fi.Try())
- {
- TDocumentSecondStomach* s = (TDocumentSecondStomach*) fDocument;
-
- EachSubView (SendConfigChange, (void*) s);
-
- inherited::DoEvent(eventNumber,source,event);
- fi.Success();
- }
- else
- {
- // Bad Config parameter
- // Leave the dialog up
- }
- }
- else
- inherited::DoEvent(eventNumber,source,event);
- }
-
- /***********************************|****************************************/
-
- pascal void SetConfigStringFromServer(TView* theSubView, void* staticLink)
- {
- CStr255 info;
-
- if (IsViewIdentifierAConfigItem ( theSubView->fIdentifier ) )
- {
- TDocumentSecondStomach* s = (TDocumentSecondStomach*) staticLink;
-
- s->GetConfigValue(theSubView);
- }
- else
- {
- }
-
- theSubView->EachSubView (SetConfigStringFromServer, (void*) staticLink );
- }
-
- pascal void TDialogViewConfig::Open()
- {
- TDocumentSecondStomach* s = (TDocumentSecondStomach*) fDocument;
-
- EachSubView (SetConfigStringFromServer, (void*) s);
-
- inherited::Open();
- }